<!DOCTYPE html>
<html lang="en">
<head>
    <title>待查收入</title>
    <#include "../inc/header.ftl"/>
    <link rel="stylesheet" href="${prefix}/assets/custom/css/main.css" />
</head>

<body class="no-skin">

<div class="main-container ace-save-state" id="main-container">

    <div class="main-content">
        <div class="main-content-inner">

            <div class="page-content">
                <table width="1000" border="0" align="center" cellpadding="0" cellspacing="0" class="r_tablebr">
                    <tr>
                        <td valign="top" class="r_nr">
                            <table width="99%" border="0" cellpadding="0" cellspacing="0" class="r_zsdwbm">
                                <tr>
                                    <td width="35%" align="left">行政区划：
                                        <input name="cantoncode" type="text"  id="cantoncode" value="" style="width:60px" /></td>
                                    <td width="35%" align="center">银行账户：
                                        <input name="bankid" id="bankid" class="easyui-combobox" style="width:80%"/></td>
                                    <td width="25%" align="right">业务日期：
                                        <input id="paybankdt" name="paybankdt" class="easyui-datebox" style="width:100px"></td>
                                    <td align="left">
                                        <input type="button" name="button" id="button" class="r_button" onclick="queryWaitaffirmData()" value="查询单据" /> </td>
                                </tr>
                            </table>
                            <div style="overflow-y:auto; overflow-x:auto; width:1000px; height:330px;float:left">
                                <table width="99%" border="1" cellspacing="1" cellpadding="0" class="r_dcsqr" style="margin:auto" id="tab">
                                    <tr>
                                        <td width="80" align="center">付款人</td>
                                        <td align="center" width="180">付款账号</td>
                                        <td align="center">开户银行</td>
                                        <td align="center">收款网点</td>
                                        <td align="center" width="150">交易流水号</td>
                                        <td align="center" width="80">收款日期</td>
                                        <td align="center" width="80">收款方式</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                </table>
                            </div>
                            <form name="waitaffirmForm" id="waitaffirmForm" action="saveWaitaffirmData" method="post">
                                <table width="99%" border="1" cellpadding="0" cellspacing="1" class="r_jcxx">
                                    <tr>
                                        <td width="80" align="right">付款人</td>
                                        <td width="130"><input name="payer" type="text" id="payer" style="width:120px;" onkeydown="if(event.keyCode==13){document.getElementById('payeraccount').focus();}"/></td>
                                        <td width="80" align="right">付款账号</td>
                                        <td><input name="payeraccount" type="text" id="payeraccount" style="width:180px;"  onkeydown="if(event.keyCode==13){document.getElementById('payerbank').focus();}"/></td>
                                        <td align="right" width="80">开户银行</td>
                                        <td><input name="payerbank" type="text" id="payerbank" style="width:180px;"  onkeydown="if(event.keyCode==13){document.getElementById('payway').focus();}"/></td>
                                    </tr>
                                    <tr>
                                        <td align="right">付款方式</td>
                                        <td><input name="payway" type="text" id="payway" class="r_input2" style="width:80px"/></td>
                                        <td align="right">交易流水号</td>
                                        <td><input name="bankaffirm" type="text" id="bankaffirm" style="width:120px;"  onkeydown="if(event.keyCode==13){document.getElementById('originfund').focus();}"/></td>
                                        <td align="right">金额</td>
                                        <td><input name="originfund" type="text" id="originfund" style="width:120px;" /></td>
                                    </tr>
                                </table>
                                <table width="99%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td height="40" align="right"><input type="button" name="button1" id="button1"  class="r_button" onclick="pay()" value="保存" />
                                            <input type="button" name="button4" id="button4"  class="r_button" value="关闭" /></td>
                                    </tr>
                                </table>
                        </td>
                    </tr>
                </table>
            </div><!-- /.page-content -->

        </div>
    </div><!-- /.main-content -->
</div><!-- /.main-container -->

<!-- basic scripts -->
<#include "../inc/basicjs.ftl"/>
<script src="${prefix}/assets/custom/js/commonview.js"></script>
<script type="text/javascript">
    //---区划三级下拉框
    $('#cantoncode').combotree({
        url:prefix+'/base/basedata/findUserCantonMap',
        required: true,
        width: 200
    });
    //缴款方式下拉框
    $('#payway').combobox({
        url:prefix + '/base/basedata/findPayWay',
        valueField:'paywayid',
        textField:'paywayname',
        panelHeight:'auto',
        onLoadSuccess:function(){
            var data = $('#payway').combobox('getData');//获取所有下拉框数据
            if (data.length > 0) {
                //如果有数据的话默认选中第一条数据
                $('#payway').combobox('select',data[0].paywayid);
            }
        }
    });

    $('#cantoncode').combo({
        onChange: function(){
            var t = $('#cantoncode').combotree('tree');	// get the tree object
            var n = t.tree('getSelected');
            $('#bankid').combobox({
                url: prefix+'/base/basedata/findBankVoView?cantonid='+n.id,
                valueField:'bankid',
                textField:'bankname'
            });
        }
    })
    $(function(){
        var curr_time = new Date();
        var str = curr_time.getFullYear()+"-";
        str += curr_time.getMonth()+1+"-";
        str += curr_time.getDate()+"-";
        $('#paybankdt').datebox('setValue',str);
    });

    var rowcount=0;
    var onerow = "";

    function queryWaitaffirmData() {
        var bankid = $("#bankid").val();
        if(bankid=="0" || bankid=="") {
            alert("请选择银行账号！");
            return;
        }
        var paybankdt = $("#paybankdt").val();
        if(paybankdt=="") {
            alert("请选择业务日期！");
            return;
        }
        $.ajax({
            type: "POST",
            url: prefix+"/view/waitaffirm/queryHistWaitaffirmData",
            dataType: "json",
            data: { bankid: bankid,paybankdt:paybankdt},
            success: function (dataOne) {
                var data =new DOMParser().parseFromString(dataOne.data, "text/xml")
                if(rowcount!=0) {
                    rowcount = 0;
                    var tLength = $("#tab tr").length;
                    for(i=tLength-1;i>=1;i--) {
                        $("#tab tr:eq("+i+")").remove();
                    }
                }
                if($(data)=="") {
                    return;
                }
                var bills_length = $(data).find("bill").length;
                if(bills_length<1){
                    return;
                }
                $(data).find("bill").each(function(i, ele) {     //查找所有节点并遍历
                    onerow = "<tr>"
                        +"<td align='center'>"+$(ele).find("payer").text()+"</td>"
                        +"<td align='center'>"+$(ele).find("payeraccount").text()+"</td>"
                        +"<td>"+$(ele).find("payerbank").text()+"</td>"
                        +"<td>"+$(ele).find("bankname").text()+"</td>"
                        +"<td align='center'>"+$(ele).find("bankaffirm").text()+"</td>"
                        +"<td align='center'>"+$(ele).find("paybankdt").text()+"</td>"
                        +"<td align='center'>&nbsp;</td>"
                        +"</tr>";
                    if(rowcount<=11){
                        $("#tab tr:eq("+(rowcount+1)+")").remove();
                    }
                    $(onerow).insertAfter($("#tab tr:eq("+rowcount+")"));
                    rowcount++;
                });
                if(bills_length<12) {
                    while(rowcount<=11) {
                        onerow = "<tr>"
                            +"<td align='center'>&nbsp;</td>"
                            +"<td align='center'>&nbsp;</td>"
                            +"<td>&nbsp;</td>"
                            +"<td>&nbsp;</td>"
                            +"<td align='center'>&nbsp;</td>"
                            +"<td align='center'>&nbsp;</td>"
                            +"<td align='center'>&nbsp;</td>"
                            +"</tr>";
                        if(rowcount<=11) {
                            $("#tab tr:eq("+(rowcount+1)+")").remove();
                        }
                        $(onerow).insertAfter($("#tab tr:eq("+rowcount+")"));
                        rowcount++;
                    }
                    rowcount = bills_length;
                }
            }
        })
    }

    function pay() {
        var bankid = $("#bankid").val();
        var t = $('#cantoncode').combotree('tree').tree('getSelected');	// get the tree object
        var payer = $("#payer").val();//类型=String；付款人。
        var payeraccount = $("#payeraccount").val();//类型=String；付款账号。
        var payerbank = $("#payerbank").val();//类型=String；付款开户行。
        var accountcode = $("#accountcode").val();//类型=String；收款账号。
        var bankaffirm = $("#bankaffirm").val();//类型=String；交易流水号
        var originfund = $("#originfund").val();//类型=String；金额。
        var payway = $("#payway").val();//类型=String；缴费类型编码。
        var paybankdt = $("#paybankdt").val();//类型=String；收款时间YYYY-MM-DDhh24:mm:ss
        var form = $("form[name=waitaffirmForm]");
        var cantoncode = $("#cantoncode").val();
        if(cantoncode=="") {
            alert("请先选择行政区划！");
            return;
        }
        if(accountcode=="" || accountcode=="0") {
            alert("请选择银行账号！");
            return;
        }
        if(payer=="") {
            alert("请填写付款人！");
            return;
        }
        if(originfund=="") {
            alert("请填写金额！");
            return;
        }
        if (originfund < 0 || originfund == 0) {
            alert("金额不能为0或负数！");
            return;
        }

        $('#waitaffirmForm').form({
            url:prefix+ '/view/waitaffirm/saveWaitaffirmData',
            onSubmit:function(param){
                param.bankid =bankid;
                param.cantonid=t.id;
                param.paybankdt =paybankdt;
                var isValid = $(this).form('validate');
                if (isValid){
                    $.messager.progress({
                        title: '提示',
                        msg: '数据处理中，请稍候……',
                        text: ''
                    });
                }
                return isValid;
            },
            success:function(data) {
                $.messager.progress('close');
                var data = eval('(' + data + ')');
                if(data.success) {
                    location=prefix+'/view/waitaffirm/waitaffirmview';
                }
                alert(data.msg);
            }
        });
        $('#waitaffirmForm').submit();

    }
</script>
</body>
</html>
